package com.ad.search.controller;

import com.ad.common.annotation.IgnoreResponseAdvice;
import com.ad.common.vo.CommonResponse;
import com.ad.search.client.SponsorClient;
import com.ad.common.vo.AdPlan;
import com.ad.common.vo.AdPlanGetRequest;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: megan
 * @mail: meganmail@vip.qq.com
 * @date: 2019/4/2 16:23
 * @version: v1.0
 * @description:
 */
@Slf4j
@RestController
public class SearchController {
    @Resource
    private RestTemplate restTemplate;
    @Resource
    private SponsorClient sponsorClient;

    @PostMapping("/getAdPlans")
    @IgnoreResponseAdvice
    public CommonResponse<List<AdPlan>> getAdPlans(@RequestBody AdPlanGetRequest adPlanGetRequest) {
        log.info("ad:search getAdPlans : {}", JSON.toJSONString(adPlanGetRequest));
        CommonResponse<List<AdPlan>> commonResponse = sponsorClient.getAdPlans(adPlanGetRequest);
        return commonResponse;
    }

    @SuppressWarnings("all")
    @IgnoreResponseAdvice
    @PostMapping("/getAdPlansByRibbon")
    public CommonResponse<List<AdPlan>> getAdPlansByRibbon(@RequestBody AdPlanGetRequest adPlanGetRequest) {
        log.info("ad:search getAdPlansByRibbon : {}", JSON.toJSONString(adPlanGetRequest));
        return restTemplate.postForEntity("http://eureka-client-ad-sponsor/ad-sponsor/get/adPlan",
                adPlanGetRequest, CommonResponse.class).getBody();
    }


}
